#ifndef _RETRO_PLAYER_FRAME
#define _RETRO_PLAYER_FRAME

#include "player.h"
#include "player.gridmap.h"

namespace Retro
{
  namespace Player
  {
    class Frame : Window
    {
    private:
      static Frame*   sFrame;

      Audio::AudioDevice*       mAudio;
      Display::DisplayDevice*   mDisplay;
      Data::RetroProject        mProject;
      TCHAR                     mProjectPath[MAX_PATH + 1];

      WrapWnd   mEditor;
      BOOL      mRun;
      BOOL      mEmbed;
      BOOL      mPause;
      DOUBLE    mDeltaTime;
      LONGLONG  mLastTime;

      BOOL  openProject(PCTSTR path);
      VOID  closeProject();

      VOID  initDisplay();
      VOID  initAudio();
      VOID  runGameLoop();

      VOID  embed();
      VOID  detach();
      VOID  initialize();

      Frame();
      INL ~Frame() {}

    protected:
      virtual VOID  onDestroy();
      virtual VOID  onEraseBackground(Event::EraseBackgroundEvent& iEvent);
      virtual VOID  onMouseDown(Event::MouseEvent& iEvent);
      virtual VOID  onActivateApp(Event::ActivateAppEvent& iEvent);
      virtual VOID  wndProc(Event::WndProcEvent& iEvent);

    public:
      VOID  resetFrame();
      VOID  setFullscreen(BOOL iFullscreen);

      INL DOUBLE  getDeltaTime()
      {
        return mDeltaTime;
      }

      INL Data::RetroProject& getProject()
      {
        return mProject;
      }

      INL Display::DisplayDevice* getDisplay()
      {
        return mDisplay;
      }

      INL BOOL  isRunning()
      {
        return mRun;
      }

      static INL Frame* get()
      {
        return sFrame;
      }
      static WPARAM     start(LPCTSTR iFilename, BOOL iEmbed);

      INL VOID  stop()
      {
        mRun = FALSE;
      }
    };
  }
}

#endif
